using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model.DataInterfaces.CompanyDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class InsuranceController : Controller
    {
		private readonly IPatientRepository patientRepository;
		private readonly ICompanyRepository companyRepository;
		private readonly IInsurancePlanRepository insuranceplanRepository;
		private readonly IInsuranceCategoryRepository insurancecategoryRepository;
		private readonly IInsuranceStatusRepository insurancestatusRepository;
		private readonly IInsuranceRepository insuranceRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public InsuranceController()// : this(new PatientRepository(), new CompanyRepository(), new InsurancePlanRepository(), new InsuranceCategoryRepository(), new InsuranceStatusRepository(), new InsuranceRepository())
        {
            this.patientRepository = Registry.RepositoryFactory.GetPatientRepository();
            this.companyRepository = Registry.RepositoryFactory.GetCompanyRepository();
            this.insuranceplanRepository = Registry.RepositoryFactory.GetInsurancePlanRepository();
            this.insurancecategoryRepository = Registry.RepositoryFactory.GetInsuranceCategoryRepository();
            this.insurancestatusRepository = Registry.RepositoryFactory.GetInsuranceStatusRepository();
            this.insuranceRepository = Registry.RepositoryFactory.GetInsuranceRepository();
        }

        public InsuranceController(IPatientRepository patientRepository, ICompanyRepository companyRepository, IInsurancePlanRepository insuranceplanRepository, IInsuranceCategoryRepository insurancecategoryRepository, IInsuranceStatusRepository insurancestatusRepository, IInsuranceRepository insuranceRepository)
        {
			this.patientRepository = patientRepository;
			this.companyRepository = companyRepository;
			this.insuranceplanRepository = insuranceplanRepository;
			this.insurancecategoryRepository = insurancecategoryRepository;
			this.insurancestatusRepository = insurancestatusRepository;
			this.insuranceRepository = insuranceRepository;
        }

        //
        // GET: /Insurance/

        public ViewResult Index()
        {
            return View(insuranceRepository.All);//Including(insurance => insurance.Patient, insurance => insurance.Company));
        }

        //
        // GET: /Insurance/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(insuranceRepository.Find(id));
        }

        //
        // GET: /Insurance/Create

        public ActionResult Create()
        {
			ViewBag.PossiblePatients = patientRepository.All;
			ViewBag.PossibleCompanies = companyRepository.All;
			ViewBag.PossibleInsurancePlans = insuranceplanRepository.All;
			ViewBag.PossibleInsuranceCategories = insurancecategoryRepository.All;
			ViewBag.PossibleInsuranceStatus = insurancestatusRepository.All;
            return View();
        } 

        //
        // POST: /Insurance/Create

        [HttpPost]
        public ActionResult Create(Insurance insurance)
        {
            if (ModelState.IsValid) {
                insuranceRepository.Create(insurance);
                insuranceRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossiblePatients = patientRepository.All;
				ViewBag.PossibleCompanies = companyRepository.All;
				ViewBag.PossibleInsurancePlans = insuranceplanRepository.All;
				ViewBag.PossibleInsuranceCategories = insurancecategoryRepository.All;
				ViewBag.PossibleInsuranceStatus = insurancestatusRepository.All;
				return View();
			}
        }
        
        //
        // GET: /Insurance/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossiblePatients = patientRepository.All;
			ViewBag.PossibleCompanies = companyRepository.All;
			ViewBag.PossibleInsurancePlans = insuranceplanRepository.All;
			ViewBag.PossibleInsuranceCategories = insurancecategoryRepository.All;
			ViewBag.PossibleInsuranceStatus = insurancestatusRepository.All;
             return View(insuranceRepository.Find(id));
        }

        //
        // POST: /Insurance/Edit/5

        [HttpPost]
        public ActionResult Edit(Insurance insurance)
        {
            if (ModelState.IsValid) {
                insuranceRepository.Update(insurance);
                insuranceRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossiblePatients = patientRepository.All;
				ViewBag.PossibleCompanies = companyRepository.All;
				ViewBag.PossibleInsurancePlans = insuranceplanRepository.All;
				ViewBag.PossibleInsuranceCategories = insurancecategoryRepository.All;
				ViewBag.PossibleInsuranceStatus = insurancestatusRepository.All;
				return View();
			}
        }

        //
        // GET: /Insurance/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(insuranceRepository.Find(id));
        }

        //
        // POST: /Insurance/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var insu = insuranceRepository.Find(id);
            insuranceRepository.Delete(insu);
            insuranceRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

